package com.jeecg.p3.baseApi.util;

import org.springframework.web.multipart.MultipartFile;

import java.util.Base64;

/**
 * @author zhuzhe
 * @date 2018/10/17 17:21
 * @email zhe.zhu1@outlook.com
 */
public class Base64Utils {

    public static MultipartFile base64ToMultipart(String base64) {
        String[] baseStr = base64.split(",");

        Base64.Decoder decoder = Base64.getDecoder();
        byte[] b;
        b = decoder.decode(baseStr[1]);

        for (int i = 0; i < b.length; ++i) {
            if (b[i] < 0) {
                b[i] += 256;
            }
        }
        return new Base64DecodeMultipartFile(b, baseStr[0]);
    }
}
